package com.hs.controller;


import com.hs.entity.pojo.Dialogue;
import com.hs.entity.vo.DialogueVO;
import com.hs.service.DialogueService;
import com.hs.utils.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hs
 * @since 2023-08-05
 */
@RestController
@RequestMapping("/dialogue")
@Api(tags = "对话")
public class DialogueController {

    @Resource
    private DialogueService dialogueService;

    @PostMapping("/create")
    @ApiOperation("创建对话")
    public ResultResponse<?> createDialogue(@RequestParam Integer theOne,@RequestParam Integer theOther){
        Dialogue dialogue = new Dialogue();
        dialogue.setTheOneUserId(theOne);
        dialogue.setTheOtherUserId(theOther);
        dialogueService.save(dialogue);
        return ResultResponse.ok();
    }

    @GetMapping("/getDialogueList")
    @ApiOperation("查询当前用户对话列表")
    public ResultResponse<List<DialogueVO>> getCurrentUserDialogueList(){
        return dialogueService.getCurrentUserDialogueList();
    }

    @GetMapping("/getDialogueIdByUserIds")
    @ApiOperation("根据两个用户ID查询对应对话ID")
    public ResultResponse<Integer> getDialogueIdByUserIds(@RequestParam("theOne") Integer theOne,@RequestParam("theOther") Integer theOther){
        return dialogueService.getDialogueIdByUserIds(theOne,theOther);
    }
}

